const app = getApp();
Page({
	data: {
		g_iphone: '',
		page: 1
	},
	onLoad: function(options) {
		var that = this;
		this.options = options;
		if (options.goods == 'true') {
			wx.setNavigationBarTitle({
				title: '兑换名单'
			})
			app.request(app.apiDomain + 'index.php?c=mall&a=orderUser', {
				goods_id: options.common,
				page: 1
			}, function(res) {
				console.log(res.data)
				console.log(options.goods)
				that.setData({
					likes: res.data.data,
					goods: options.goods
				});
			});
		} else {
			if (options.common) { //圈子点赞
				app.request(app.apiDomain + 'index.php?c=group&a=zanlist', {
					page: 1,
					size: 20,
					article_id: options.common
				}, function(res) {
					console.log(res)
					if (res.data.status == '1') {
						that.setData({
							likes: res.data.data,
							goods: options.goods
						});
					}
				});
			} else {
				if (options.lottery_id) { // 抽奖人员列表
					console.log('抽奖人员列表')
					wx.setNavigationBarTitle({
						title: '抽奖人员列表'
					})
					app.request(app.apiDomain + 'index.php?c=lottery&a=drawUser', {
						lottery_id: options.lottery_id,
						page: 1,
						size: 20
					}, function(res) {
						console.log(res)
						that.setData({
							likes: res.data.data.list,
							goods: options.goods,
							lottery_id: options.lottery_id
						})
					});
				} else {
					//个人中心 点赞
					app.request(app.apiDomain + 'index.php?c=user&a=likeusers', {}, function(res) {
						if (res.data.status == '1') {
							that.setData({
								likes: res.data.data,
								goods: options.goods
							});
						}
					});
				}
			}
		}
	},
	onReady: function() {
		app.SystemInfo(this)
	},
	onShareAppMessage: function() {
		return app.onShareAppMessage();
	},
	// 抽奖人员加载
	onReachBottom() {
		var that = this
		if(this.options.goods == 'true'){
			app.request(app.apiDomain + 'index.php?c=mall&a=orderUser', {
				goods_id: options.common,
				page: this.data.page + 1,
				size: 20,
			}, function(res) {
				that.setData({
					likes:that.data.likes.concat(res.data.data),
				});
			});
		}else if (this.data.lottery_id) {
			var that = this
			app.request(app.apiDomain + 'index.php?c=lottery&a=drawUser', {
				lottery_id: this.data.lottery_id,
				page: this.data.page + 1,
				size: 20,
			}, res => {
				console.log(res)
				if (res.data.data.length == 0) {
					wx.showToast({
						title: '没有更多了~',
						icon: 'none',
						duration: 2000
					})
					return false
				}
				that.setData({
					page: this.data.page + 1,
					// 商品列表
					likes: this.data.likes.concat(res.data.data.list)
				})
			})
		}
	}
})
